# Maintainer: Megavolt <max.megavolt@posteo.de>

_appname=eddie-ui
pkgname=${_appname}-appimage
pkgver=2.21.6
pkgrel=1
pkgdesc='Eddie - VPN tunnel - UI'
arch=('x86_64')
url='https://eddie.website/'
license=(GPLv3)
depends=('libappindicator-gtk2')
optdepends=('')
provides=("${pkgname}")
conflicts=('airvpn-bin' 'airvpn-beta-bin' 'eddie-ui-git' 'eddie-ui')
_filename="${_appname}-${pkgver}-${CARCH}.AppImage"
source=("${_filename}::https://eddie.website/download/?platform=linux&arch=x64&ui=ui&format=appimage.AppImage&version=${pkgver}")
sha1sums=('6b30eb3ad6dae3b1e61cbc0b43f92e758b7d35a4')



prepare() {
	# Extract AppImage
  cd "${srcdir}"
  chmod +x ${_filename}
  eval ./${_filename} --appimage-extract "${_appname}.desktop"
  eval ./${_filename} --appimage-extract "${_appname}.png"
}

package() {

  # Install AppImage
  install -Dm755 "${srcdir}/${_filename}" "${pkgdir}/opt/AppImages/${_filename}"
  mkdir -p "${pkgdir}/usr/bin/"
  ExecScript="#!/bin/sh\nexec /opt/AppImages/${_filename} \"\$@\""
  echo -e $ExecScript > "${pkgdir}/usr/bin/${_appname}"
  chmod +x "${pkgdir}/usr/bin/${_appname}"
  #install -Dm755 "${srcdir}/${_appname}" "${pkgdir}/usr/bin/${_appname}"
  
  # Install Desktop
  install -Dm644 "${srcdir}/squashfs-root/${_appname}.desktop" "${pkgdir}/usr/share/applications/${_appname}.desktop"
  
  # Install Icon
  icon_size="$(identify -format '%wx%h' ${srcdir}/squashfs-root/${_appname}.png)"
  install -Dm644 "${srcdir}/squashfs-root/${_appname}.png" "${pkgdir}/usr/share/icons/hicolor/${icon_size}/apps/${_appname}.png"

}

